import login from "@/api/login";

export default {
    name: "index",
    created() {
        this.getCode();

    },
    data() {
        return {
            codeImg: '',
            loginFrom: {
                uuid: ''
            }
        }
    },
    methods: {
        async doLogin() {
            let token = await login.doLogin(this.loginFrom);
            localStorage.setItem("token", token);

            let response = await login.getUserInfo()
            console.log(response);

            let admin = response.admin
            localStorage.setItem("admin", JSON.stringify(admin))
            //
            let menuList = response.menuList;

            let btnList = response.btnList;
            //
            localStorage.setItem("btnList", JSON.stringify(btnList));
            localStorage.setItem("menuList", JSON.stringify(menuList));

            this.$router.push("/main/index");
        },
        async getCode() {
            this.loginFrom.uuid = this.guid();
            this.codeImg = await login.getCode(this.loginFrom.uuid);
        },
        guid() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                var r = Math.random() * 16 | 0,
                    v = c == 'x' ? r : (r & 0x3 | 0x8);
                return v.toString(16);
            });
        }
    }
}
